/*************************************************************************
	> File Name: P1322.cpp
	> Author: yufangze
	> Mail: 2224590123@qq.com
	> Created Time: 2025-02-11 11:39:29
 ************************************************************************/

#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int solve(string str) {
    int ans = 0, add = 0;
    for (int i = 0; i < str.size(); i++) {
        switch (str[i]) {
            case ' ': break;
            case 'F': {
                i += 3;
                int temp = 0;
                while (str[i] >= '0' && str[i] <= '9') {
                    temp = temp * 10 + (str[i] - '0');
                    i++;
                }
                i -= 1;
                ans += temp;
            } break;
            case 'B': {
                i += 3;
                int temp = 0;
                while (str[i] >= '0' && str[i] <= '9') {
                    temp = temp * 10 + (str[i] - '0');
                    i++;
                }
                i -= 1;
                ans -= temp;
                ans = abs(ans);
            } break;
            case 'R': {
                i += 7;
                int temp = 0;
                while (str[i] >= '0' && str[i] <= '9') {
                    temp = temp * 10 + (str[i] - '0');
                    i++;
                }
                i -= 1;
                add = temp;
            } break;
            case '[': {
                int temp = add * solve(str.substr(i + 1));
                ans += temp;
                while (str[i] != ']') i++;
            } break;
            case ']': return ans;
        }
    }
    return ans;
}

int main() {
    string str;
    getline(cin, str);
    int ans = solve(str);
    cout << ans << endl;
    return 0;
}
